package itb.fhv.sa.pipesfilters;

import java.util.Vector;

public class Word implements PLOutput {

	private String m_word;


	public Word(String word) {
		m_word = word;
	}


	public String getContent() {
		return m_word;
	}


	private Vector<Integer> getVowelPositions() {

		Vector<Integer> vec = new Vector<Integer>();
		int strlen = m_word.length();
		boolean noLetter = false;
		boolean foundvowel = false;
		char[] vowels = { 'a', 'e', 'i', 'o', 'u' };
		String wordToSplit = m_word.toLowerCase();

		for (int i = 0; i < strlen; i++) {
			for (int j = 0; j < 4; j++) {
				if (wordToSplit.charAt(i) == vowels[j]) {
					foundvowel = true;
				}
				if (wordToSplit.charAt(i) < 'a' || wordToSplit.charAt(i) > 'z') {
					noLetter = true;
				}
			}
			if (noLetter == true) {
				vec.clear();
				return null;
			} else if (foundvowel == true) {
				vec.add(1);
			} else {
				vec.add(0);
			}
			foundvowel = false;
		}
		return vec;
	}


	public String[] splitWord() {
		String[] result = {null, null};
		
		//
		Vector<Integer> vec = new Vector<Integer>();
		vec = getVowelPositions();

		if (vec != null && (vec.size() >= 4)) {
			int splitInd = 1;				
			boolean found = false;

			while (splitInd < (vec.size() - 1) && found == false) {

				if (vec.elementAt(splitInd) == 0
						&& vec.elementAt(splitInd + 1) == 0) {
					found = true;
				} else if (vec.elementAt(splitInd) == 1) {
					found = true;
				}

				splitInd++;
			}

			result[0] = m_word.substring(0, splitInd) + "- ";
			result[1] = m_word.substring(splitInd, m_word.length())	+ " ";
		}
		
		return result;
	}
	
	
//	public void removeControlCharacter() {
//		m_word = m_word.substring(0, m_word.length() - 1);
//	}

}
